#!/bin/sh
# get current song title and artist from cmus otherwise 'paused'

query=$(cmus-remote -Q 2>/dev/null)
# quit if cmus is not running
[ $? -ne 0 ] && exit 1

# get title and artist
IFS=$(printf '\v') read -r status title artist << EOF
$(printf '%s' "${query}" \
	| sed -n 's/^\(status\|tag \(title\|artist\)\) //p' \
	| tr '\n' '\v' \
)
EOF

# print at most 20 characters of title and artist each
[ "${status}" = playing ] \
	&& printf '%s - %s\n' "${title:0:20}" "${artist:0:20}" \
	|| printf 'paused\n'
